package com.sixseven.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sixseven.bean.Comment;
import com.sixseven.bean.Member;
import com.sixseven.mapper.CommentMapper;
import com.sixseven.service.CommentService;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

/**
 * @author Belly
 * @version 1.1.0
 */
@Service
public class CommentServiceImpl extends ServiceImpl<CommentMapper, Comment> implements CommentService {
    @Override
    public int addComment(String message, Integer announcementId, HttpServletRequest request) {
        Member member = (Member) request.getSession().getAttribute("member");
        if (member == null){
            return -1;
        }
        Comment comment =
                new Comment(null, member.getUsername(),
                        new Date(), message, member.getId(), announcementId);
        if (comment == null){
            return -1;
        }
        //保存评论
        return this.save(comment) ? 1 : -1;
    }
}
